<template>
  <el-container class="home">
    <el-header class="header">
      <div style="font-size: 20px;">Vue、Element、Spring Boot权限管理系统开发实战</div>
      <div class="headerRight">
        <el-dropdown placement="top-start">
          <span class="el-dropdown-link">
            <img class="userImgs el-icon-arrow-down" src="../assets/avatar.jpg" alt="">
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item>退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <div class="userInformation">
          <div class="userNames">欢迎您：墨湮</div>
          <div>{{date}}</div>
        </div>
      </div>
    </el-header>
    <el-container>
      <el-aside class="aside" width="auto">
        <menu-bar></menu-bar>
      </el-aside>
      <el-container>
        <el-main class="main">
          <i class="arrowIcon" :class="[isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold']" @click="iconClick"></i>
        </el-main>
        <el-footer class="footer" height='40px'>
          Copyright &copy; 2020 - 2021 . 秘咖学堂.All Rights Reserved
        </el-footer>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
  import MenuBar from '../components/MenuBar.vue'
  import {mapState} from 'vuex'

  let $vueIndex;
  export default {
    name: 'Home',
    components: {
      MenuBar
    },
    data () {
      return {
        date: ""
      }
    },
    computed: {
      ...mapState({
        isCollapse: state => state.MenuStore.isCollapse
      })
    },
    mounted() {
      $vueIndex = this;
      this.showTime();
      setInterval(function () {
        $vueIndex.showTime();
      }, 1000);
    },
    methods: {
      iconClick() {
        this.$store.commit('setOpenOrCLose');
      },
      showTime() {
        var week = new Array(
          "星期日",
          "星期一",
          "星期二",
          "星期三",
          "星期四",
          "星期五",
          "星期六"
        );
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var hour = date.getHours();
        var minutes = date.getMinutes();
        var second = date.getSeconds();
        
        this.date = `${year}.${(month < 10 ? "0" + month : month)}.${day}
                            ${hour}:${minutes}:${(second < 10 ? "0" + second : second)}
                            ${(week[date.getDay()] || "")}`;
      },
    },
  }

</script>

<style scoped>
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
  .home {
    height: 100%;
  }
  .header {
    color: #FFF;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #167bd8;
  }
  .headerRight {
    display: flex;
  }
  .userInformation {
    display: flex;
    flex-flow: column;
    justify-content: center;
    margin: 0 10px;
  }
  .userImgs {
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
  .userNames {
    font-weight: 600;
  }
  .aside {
    border-right: 1px solid #c6c6c6;
  }
  .main {
    padding: 0;
  }
  .arrowIcon {
    float: left;
    background-color: #eaedf1;
    border: 1px solid transparent;
    font-size: 23px;
    height: 39px;
    line-height: 39px !important;
    width: 40px;
    text-align: center;
  }
  .footer {
    color: #FFF;
    background-color: rgb(189, 178, 103);
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>